//
//  FirstSearActiTableViewCell.m
//  Project_B
//
//  Created by 张闯的mac pro on 15/12/1.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "FirstSearActiTableViewCell.h"
#import "FirstModel.h"
#import "UIImageView+WebCache.h"

@interface FirstSearActiTableViewCell ()
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *dtime;
@property (nonatomic, strong) UIImageView *image;
@end

@implementation FirstSearActiTableViewCell


#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:self.title];

        
        self.dtime = [[UILabel alloc] init];
        [self.contentView addSubview:self.dtime];

        
        self.image = [[UIImageView alloc] init];
        [self.contentView addSubview:self.image];

    }
    return self;
}
#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.image.frame = CGRectMake(10, 15, 150, 100);
    self.image.contentMode = UIViewContentModeScaleAspectFill;
    self.image.layer.cornerRadius = 5;
    self.image.clipsToBounds = YES;
    
    
    self.title.frame = CGRectMake(self.image.frame.origin.x + self.image.frame.size.width + 10, 30, self.contentView.frame.size.width - self.image.frame.size.width - 50, 50);
    self.title.numberOfLines = 0;
    self.title.font = [UIFont systemFontOfSize:15];
    //    self.title.textColor = [UIColor grayColor];
    
    self.dtime.frame = CGRectMake(self.image.frame.origin.x + self.image.frame.size.width + 10, self.title.frame.origin.y + self.title.frame.size.height + 5, self.contentView.frame.size.width - self.image.frame.size.width - 50, 15);
    self.dtime.font = [UIFont systemFontOfSize:15];
    self.dtime.textColor = [UIColor grayColor];
    
}
#pragma mark - 赋值
- (void)setRootModel:(FirstModel *)rootModel
{
    if (_rootModel != rootModel) {
        _rootModel = rootModel;
    }
    //    self.title.text = rootModel.title;
    [self.title sizeToFit];
    self.dtime.text = rootModel.dtime;
    [self.image sd_setImageWithURL:[NSURL URLWithString:rootModel.image] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
    //关键字高亮
    NSString *string = rootModel.title;
    NSMutableAttributedString *newString = [[NSMutableAttributedString alloc] initWithString:string];
    //得到关键字位置
    NSRange range = [string rangeOfString:self.searchText];
    [newString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1] range:range];
    self.title.textColor = [UIColor grayColor];
    self.title.attributedText = newString;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
